package edu.sdjzu.exam.mapper.examSession;




import edu.sdjzu.exam.domain.examSession.ExamSession;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ExamSessionMapper {

    @Insert("INSERT INTO Exam_Sessions (exam_id, student_id, start_time, end_time, remaining_time, ip_address, device_info, status, video_stream_url) " +
            "VALUES (#{examId}, #{studentId}, #{startTime}, #{endTime}, #{remainingTime}, #{ipAddress}, #{deviceInfo}, #{status}, #{videoStreamUrl})")
    @Options(useGeneratedKeys = true, keyProperty = "sessionId")
    void insertExamSession(ExamSession examSession);

    @Select("SELECT * FROM Exam_Sessions WHERE session_id = #{sessionId}")
    ExamSession selectExamSessionById(Long sessionId);

    @Update("UPDATE Exam_Sessions SET status = #{status}, ip_address = #{ipAddress}, device_info = #{deviceInfo}, " +
            "end_time = #{endTime}, remaining_time = #{remainingTime}, video_stream_url = #{videoStreamUrl}, " +
            "updated_at = CURRENT_TIMESTAMP WHERE session_id = #{sessionId}")
    void updateExamSession(ExamSession examSession);

    @Select("SELECT * FROM Exam_Sessions WHERE student_id = #{studentId} AND exam_id = #{examId}")
    ExamSession selectExamSessionByStudentAndExam(@Param("studentId") Long studentId, @Param("examId") Long examId);

    @Select("SELECT * FROM Exam_Sessions WHERE exam_id = #{examId}")
    List<ExamSession> selectExamSessionsByExamId(Long examId);

    @Select("SELECT * FROM Exam_Sessions WHERE student_id = #{studentId} ORDER BY created_at DESC")
    List<ExamSession> selectExamSessionsByStudentId(Long studentId);

    // 新增方法
    @Select("SELECT * FROM Exam_Sessions WHERE status IN (#{status1}, #{status2})")
    List<ExamSession> selectExamSessionsByStatus(@Param("status1") String status1, @Param("status2") String status2);
}